<?php 
define('IN_WONDERSHARE', true);
require( '../../inc/config.inc.php');
require( '../../includes/cls_mysql.php');
$db = new cls_mysql($db_host, $db_user, $db_pass, $db_name);
if( $_GET['code'] != md5('get_spring_info') ) exit('error code!');
function add_buy($db)
{

	$sql = 'INSERT INTO buy_products(product_id,nums,product_name,product_fage,original_price,discount_price,start_discount_price,web_time,web_type,half_price) VALUES  
	("'.$_GET['product_id'].'","'.$_GET['nums'].'","'.addslashes(urldecode($_GET['product_name'])).'","'.$_GET['product_fage'].'",
	"'.$_GET['original_price'].'","'.$_GET['discount_price'].'","'.$_GET['start_discount_price'].'","'.$_GET['web_time'].'","'.$_GET['web_type'].'","'.$_GET['half_price'].'")';
	$db->query($sql);
}

function update_buy($db)
{
	$sql = 'UPDATE  buy_products  SET nums = nums + 1  WHERE product_id = '.trim($_GET['product_id']).' AND web_time = '.trim($_GET['web_time']).' AND web_type = "'.trim($_GET['web_type']).'"' ;
	$db->query($sql);
}


function get_buy($db)
{
	$date = array();
	
	$sql = 'SELECT  buy_id FROM  buy_products   WHERE web_time = '.trim($_GET['web_time']).'
	AND web_type = "'.trim($_GET['web_type']).'" ORDER BY  buy_id ASC  LIMIT 1 ';
	$buy_id = $db->getOne($sql);
	
	$sql = 'UPDATE  buy_products  SET is_first = 1 WHERE buy_id = '.$buy_id;
	$db->query($sql);

	$sql = 'UPDATE  buy_products  SET is_first = 0 WHERE buy_id != '.$buy_id.
	' AND web_time = '.trim($_GET['web_time']).' AND web_type = "'.trim($_GET['web_type']).'"' ;
	$db->query($sql);
	
	$sql = 'SELECT buy_id,is_first,product_id,nums,product_name,original_price,discount_price,half_price FROM buy_products WHERE  
	web_time = '.$_GET['web_time'].' AND web_type = "'.$_GET['web_type'].'" ORDER BY  buy_id ASC  ';
	$data = $db->getAll( $sql );
	foreach( $data as $k => $v ){
		$date[$v['buy_id']] = $v;
	}
	echo  serialize($date);
}

function get_products_info($db)
{
	$date = array();
	$sql = 'SELECT cbsid,product_name,original_price,discount_price,half_price FROM cbs_product_info  
	WHERE  cbsid = "'.$_GET['product_id'].'" AND web_type = 3 ';
	$data = $db->getAll( $sql );
	echo  serialize($data[0]);
}

function del_buy($db)
{
	if($_GET['buy_id']){
		$sql = 'DELETE FROM  buy_products  WHERE buy_id = '.$_GET['buy_id'];
		$db->query($sql);
	}
}
$fun = $_GET['fun'];
$fun( $db );
?>